//
//  ViewController.swift
//  SwiftDemo
//
//  Created by lizq on 16/7/3.
//  Copyright © 2016年 lizq. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    let constVar = 10;
    let doubleValue =  Double(12.0);
    let minInt = UInt8.min;
    let maxInt = UInt8.max;
    let languageName:String = "Swift 3.0";
    var vars:NSNumber?;
    var titleName:NSString?;
    var vDoubleValue = 120.0;
    override func viewDidLoad() {
        super.viewDidLoad()
//        let closures:Closures = Closures()
//        closures.viewDidLoad()
//        let enums:Enum = Enum()
//        enums.action()
//        let structs:ClassAndStruct = ClassAndStruct()
//        structs.action()
//        let method = Method()
//        method.action()
//        let subcript = Subscript()
//        subcript.action()
//        let inherit = Inherit();
//        inherit.action()
        
        self.setup();
    }
    
    func setup() -> Void {
        print("Enter setup func...");
        
        let button : UIButton = UIButton.init();
        button.backgroundColor = UIColor.blue;
        button.frame = CGRect.init(x: 100, y: 100, width: 100, height: 100);
        self.view.addSubview(button);
        button.addTarget(self, action:#selector(self.clickButton), for:UIControlEvents.touchUpInside);
        
        let view : UIImageView = UIImageView.init();
        view.frame = CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height);
        view.image = UIImage.init(named:"China Map.jpeg");
        view.contentMode = UIViewContentMode.center;
        self.view.addSubview(view);
        self.view.bringSubview(toFront: button);
        
        let backBarButtonItem = UIBarButtonItem.init(image: UIImage.init(named: "China Map.jpeg"), style: UIBarButtonItemStyle.done, target: self, action: #selector(self.clickButton));
        self.navigationItem.backBarButtonItem = backBarButtonItem;
        
        var tmp : NSNumber?;
        tmp = 12;
        let (x,y) = self.good(num1: 1, num2: 2);
        print("x is \(x) , y is \(y)");
    }
    
    func clickButton() -> Void {
        print("clicked button");
    }
    
    func greeting(user : String) -> String {
        return "Helle , \(user)";
    }
    
    func outFunc(_ obj:String) {
        func inFunc(_ obj1:String) {
            print("Hello \(obj1)")
        }
        inFunc(obj)
    }
    
    func stepForward(_ input:Int) -> Int {
        return input + 1
    }
    
    func stepBackward(_ input:Int) -> Int {
        return input - 1
    }
    
    
    func chooseStepFunction(_ backward:Bool) -> (Int) -> Int {
        
        return backward ?stepBackward:stepForward
    }
    
    func sayHellor(_ name:String) -> String {
        return "Hello" + " " + name;
    }
    
    func sub(_ sub1:Int,sub2:Int)->Int {
        return sub1 - sub2
    }
    
    func add(_ add1:Int,add2:Int)->Int {
        return add1 + add2
    }
    
    func sayHelloWorld() {
        print("hello world")
    }
    
    func sayGoodBye() ->() {
        print("Good Bye")
    }
    
    func good(num1 :Int ,num2 : Int) -> (x:Int,y:Int) {
        return (num1,num2);
    }
    
    func good(to string1:String , from string2:String = "Swift 3.0") {
        print(string1 + " " + string2)
    }
    
    func multiReturn(_ obj1:Int,obj2:Int) -> (sub:Int,add:Int,multy:Int) {
    
        return (obj1 - obj2,obj1 + obj2,obj1 * obj2)
    }
    
    func arithmeticMean(_ doubles:Double...) -> Double {
        var total:Double = 0;
        for number in doubles {
            total += number
        }
        return total
    }
    
    
    func alignRight(_ string:String,totalLength:Int,pad:Character) -> String {
        var string = string
        let amountToPad = totalLength - string.characters.count
        if amountToPad < 1 {
            return string
        }
        let padString = String(pad)
        for _ in 1...amountToPad {
            string = padString + string
        }
        return string
    }
    
    func swapTowInts(_ a:inout Int,b:inout Int) {
        let tmp = a
        a = b
        b = tmp
    }
    
    func printMathResult(_ sub:(Int,Int)->Int,a:Int,b:Int) {
        print("Result : \(sub(a, b))")
    }
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    

}

